<?php


class ThickboxHelper extends AppHelper {

	var $helpers = array('Javascript', 'Html');
	
	/**
	 * Set properties - DOM ID, Height and Width, Type of thickbox window - inline or ajax
	 *
	 * @param array $options
	 */
	function setProperties($options = array())
	{
		if(!isset($options['type']))
		{
			$options['type'] = 'inline';
		}
		$this->options = $options;
	}
	
	function setPreviewContent($content)
	{
		$this->options['previewContent'] = $content;
	}

	function setMainContent($content)
	{
		$this->options['mainContent'] = $content;
	}
	
	function reset()
	{
		$this->options = array();
	}
	
	function output($tag = 'a', $options = array())
	{
		extract($this->options);
		if($type=='inline')
		{
			$href = '#TB_inline?';
			$href .= '&inlineId='.$id;
		}
		elseif($type=='ajax')
		{
			$ajaxUrl = $this->Html->url($ajaxUrl);
			$href = $ajaxUrl.'?';
		}
				
		if(isset($height))
		{
			$href .= '&height='.$height;
		}
		if(isset($width))
		{
			$href .= '&width='.$width;
		}
		$thickboxInitTag = 'alt';
		if($tag=='a')
		{
			$thickboxInitTag = 'href';
		}
		$tagAttrs = array(
			'class' => 'thickbox',
			$thickboxInitTag => $href
		);
		$tagAttrs = am($options, $tagAttrs);
		
		$output = $this->Html->tag($tag, $previewContent, $tagAttrs);
		
		if($type=='inline')
		{
			if(isset($mainContent))
				$output .= '<div id="'.$id.'" style="display:none;">'.$mainContent.'</div>';
		}
		
		unset($this->options);
		
		return $output;
	}
	
	function beforeRender()
	{
		$this->Html->css('/effects/css/thickbox.css',null,array(),false);
		$this->Javascript->link('/effects/js/thickbox-compressed.js',false);
	}

}
?>